Type Objects

Each type declaration in the schema module is translated into one C++ type declaration with the same name. In addition, for each type <T> there is a C++ constant <T>_type which denotes the corresponding (persistent) object of the base type that the schema compiler has generated. It can be used to check the actual type of an object. This way of dynamic type evaluation allows a case distinction by the type of an object.

Note that for a type declared by

   typedef A B;
the constant B_type denotes the base type object for A, that means A_type == B_type.

Example:

The following C++ code checks, whether an object o that is statically declared of type sos_Object actually is of type sos_String; if so, it is explicitly converted to this type, and the method make_Cstring of this type is called. The conversion is necessary, since the method is no method of class sos_Object, so o.make_Cstring() would produce a C++ compile time error.

   sos_Object o;
   ...
   if (o.has_type (sos_String_type))
   {  sos_String  s  = sos_String::make (o);
      sos_Cstring cs = s.make_Cstring();
      cout << cs;
      delete cs;
   }

$\Box$